<form lay-filter="exchangeRecordsForm" class="layui-form model-form" id="exchangeRecordsForm">
    <input name="id" type="hidden"/>
    <div class="layui-form-item">
        <div class="layui-col-md4">
            <label class="layui-form-label">退货类型</label>
            <div class="layui-input-inline">
                <select id="returnType" name="returnType" lay-filter="returnType">
                    <option value="">请选择退货类型</option>
                </select>
            </div>
        </div>

        <div class="layui-col-md4">
            <label class="layui-form-label">关联订单编号</label>
            <div class="layui-input-inline">
                <select id="orderNo" name="orderNo" lay-filter="orderNo">
                </select>
            </div>
        </div>

        <div class="layui-col-md4">
            <label class="layui-form-label">客户名称</label>
            <div class="layui-input-inline">
                <input name="customerName" id="customerName" class="layui-input" type="text"/>
            </div>
        </div>

        <div class="layui-col-md4">
            <label class="layui-form-label">退货备注</label>
            <div class="layui-input-inline">
                <input name="returnNote" id="returnNote" class="layui-input" type="text"/>
            </div>
        </div>

        <div class="layui-col-md4">
            <label class="layui-form-label">照片</label>
            <div class="layui-input-inline">
                <input name="photo" id="photo" class="layui-input" type="file"/>
            </div>
        </div>

        <div class="layui-col-md4">
            <label class="layui-form-label">退货方式</label>
            <div class="layui-input-inline">
                <select id="returnMethod" name="returnMethod" lay-filter="returnMethod">
                </select>
            </div>
        </div>

        <div class="layui-col-md4">
            <label class="layui-form-label">物流公司</label>
            <div class="layui-input-inline">
                <input name="logisticsCompany" id="logisticsCompany" class="layui-input" type="text"/>
            </div>
        </div>

        <div class="layui-col-md4">
            <label class="layui-form-label">运单号</label>
            <div class="layui-input-inline">
                <input name="trackingNumber" id="trackingNumber" class="layui-input" type="text"/>
            </div>
        </div>

        <div class="layui-col-md4">
            <label class="layui-form-label">车牌号</label>
            <div class="layui-input-inline">
                <input name="licensePlate" id="licensePlate" class="layui-input" type="text"/>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <button class="layui-btn" style="margin-left: 20px">配置物料信息</button>
        <table class="layui-table" lay-filter="formTable" id="formTable"></table>
    </div>
    <div class="layui-form-item text-right">
        <div class="right-btn">
            <button class="layui-btn layui-btn-primary" type="button" ew-event="closeDialog">取消</button>
            <button class="layui-btn" lay-filter="productDetailSubmit" lay-submit>提交</button>
        </div>
    </div>
</form>
<script type="text/html" id="specParamInputTab">
    <div class="layui-col-md4">
        <label class="layui-form-label w-120">{{d.name}}</label>
        <div class="layui-input-inline">
            <!-- 使用动态生成的唯一ID -->
            {{# if(d.style === 'single'){ }}
            <select id="productSpecList{{d.type}}_{{ d.id }}" name="{{d.type}}"
                    lay-filter="productSpecList{{d.type}}_{{ d.id }}" class="layui-input borderNone">
            </select>
            {{# } else { }}
            <input type="text" id="productSpecList1{{d.type}}_{{ d.id }}" name="{{d.type}}"
                   class="layui-input borderNone"/>
            {{# } }}
        </div>
    </div>

</script>


<script>
    layui.use(['layer', 'form', 'table', 'admin', 'upload', 'tree', 'laytpl'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var config = layui.config;
        var admin = layui.admin;
        var upload = layui.upload;
        var laytpl = layui.laytpl;
        data = parentData.data
        form.render('select')

        // $('#productPicBtn1').click(() => {
        // });
        table.render({
            elem: '#formTable',
            data: [],
            page: true,
            cols: [[
                {tyoe: 'numbers', title: '序号', fixed: 'left'},
                {field: 'exchangeRecordCode', title: '产品编号', fixed: 'left'},
                {field: 'exchangeType', title: '规格码'},
                {field: 'logisticsRecordCode', title: '产品名称'},
                {field: 'relatedPurchaseOrderCode', title: '计价'},
                {field: 'supplierName', title: '单位'},
                {field: 'exchangeRemark', title: '退货数量'},
                {field: 'submitTime', title: '辅助单位数', sort: true},
                {field: 'exchangePerson', title: '换货人'},
                {field: 'exchangeAmount', title: '单价', sort: true},
                {field: 'status', title: '总价'},
                {field: 'status', title: '备注'},
                {align: 'center', toolbar: '#TableBar', title: '操作', fixed: 'right'}

            ]]
        })
        if (data) {

        } else {
            admin.getDictList('returnType', 'return_type', null, '退货类型')
            admin.getDictList('returnMethod', 'return_method', null, '退货方式')
            admin.req('enterprise/sell/admin/massOrder/list', {}, function (res) {
                const list = res.data
                admin.initDataSelect(list, {}, 'orderNo', null, '关联订单编号', 'code',)
                form.on('select(orderNo)', function (data) {
                    console.log(list.find(v => v.id == data.value))
                })

            })

        }
        // 表单提交事件
        form.on('submit(productDetailSubmit)', function (d) {
            console.log('data', d.field)
            var productDetailSpecList = []; //规格数组
            $("[name='tabSpecParam']").each(function () {
                var id = $(this).attr('id').split('_')[1]
                console.log(111, $(this).attr('id'))
                productDetailSpecList.push({
                    productSpecId: id,
                    productSpecValue: $(this).val()
                }); // 将值添加到数组中
            });

            var productDetailAttributeList = []; // 属性数组
            $("[name='tabAttributeParam']").each(function () {
                var id = $(this).attr('id').split('_')[1]
                productDetailAttributeList.push({
                    productAttrId: id,
                    productAttrValue: $(this).val()
                }); // 将值添加到数组中
            });
            let formData = {productDetailSpecList, productDetailAttributeList, ...d.field}
            admin.req(data ? 'enterprise/product/admin/productDetail/update' : 'enterprise/product/admin/productDetail/add', JSON.stringify(formData), function (res) {
                layer.closeAll('loading');
                if (res.code == 200) {
                    layer.msg(res.msg, {icon: 1});
                    table.reload('productDetailTable');
                    layer.closeAll('page');
                } else {
                    layer.msg(res.msg, {icon: 2});
                }
            }, data ? 'PUT' : 'POST', true, 'application/json; charset=utf-8');
            return false;
        });


    })


</script>

<style>
    .layui-form-label {
        width: 90px;
    }
</style>